package com.itheima.controller;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.itheima.pojo.Brand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/brands")
@Controller
@ResponseBody
public class BrandController {

    //查找所有 http://localhost/brands   get
    @GetMapping
    public List findall() {
        ArrayList<Brand> brands = new ArrayList<>();
        Brand brand = new Brand();
        brand.setId(1);
        brand.setBrandName("张三");
        brand.setCompanyName("黑马程序员");
        brand.setDescription("最好的培训机构");
        brands.add(brand);
        brands.add(brand);
        brands.add(brand);
        brands.add(brand);
        return brands;
    }

    //通过id查找get http://localhost/users/1
    @GetMapping("/{id}")
    public Brand findbyid(@PathVariable Integer id) {
        Brand brand = new Brand();
        brand.setId(id);
        brand.setBrandName("张三");
        brand.setCompanyName("黑马程序员");
        return brand;
    }

    /*//添加  http://localhost:8081/brands  post
    @PostMapping
    @ResponseBody
    public String save(@RequestBody Brand brand){
        System.out.println(brand);
        return "ok";
    }*/

    //删除 http://localhost:8081/brands/1
    @DeleteMapping("/{id}")
    @ResponseBody
    public String shanchu(@PathVariable Integer id) {
        System.out.println("id=" + id);
        return "delete ok";
    }

    //修改 put http://localhost/brands
    @PutMapping
    @ResponseBody
    public String update(@RequestBody Brand brand) {
        System.out.println(brand);
        return "修改成功";
    }
}



